package cn.edu.ctbu.labtest.controller;


import cn.edu.ctbu.labtest.domain.Student;

import cn.edu.ctbu.labtest.service.StudentService;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpSession;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;


import java.util.List;
@Controller
public class StudentController {
    @Autowired
    StudentService studentService;

    @RequestMapping("/student/listbak")

    public String list(Model model){
        List<Student> students=studentService.findAll();
        model.addAttribute("data",students);


        return "/student/list";
    }
//    @RequestMapping("/student/list")
    @RequestMapping("/webapi/list")

    public String list(HttpServletRequest httpServletRequest, Model model){
        HttpSession session=httpServletRequest.getSession();
        if(session.getAttribute("userid")==null){
            //没有登录，需要去输入
            return "redirect:/login/user";
        }

        List<Student> students=studentService.findAll();
        model.addAttribute("data",students);


        return "/student/list";
    }
}
